
#include <math.h>
#include "Vector3d.h"

Vector3d Vector3d_FromValues( double x, double y, double z )
{
	Vector3d v;
	v.x = x;
	v.y = y;
	v.z = z;
	return v;
};

Vector3d vector3d_normalize( Vector3d* v )
{
	Vector3d r;
	double magnitude = sqrt( (v->x*v->x) + (v->y*v->y) + (v->z*v->z) );
	r.x = v->x/magnitude;
	r.y = v->y/magnitude;
	r.z = v->z/magnitude;
	return r;
};

Vector3d Vector3d_add( Vector3d* u, Vector3d* v )
{
	Vector3d r;
	r.x = u->x + v->x;
	r.y = u->y + v->y;
	r.z = u->z + v->z;
	return r;
};

Vector3d Vector3d_sub( Vector3d* u, Vector3d* v )
{
	Vector3d r;
	r.x = u->x - v->x;
	r.y = u->y - v->y;
	r.z = u->z - v->z;
	return r;
};

double Vector3d_dot( Vector3d* u, Vector3d* v )
{
	return (u->x * v->x) + (u->y * v->y) + (u->z * v->z);
};

Vector3d Vector3d_cross( Vector3d* u, Vector3d* v )
{
	Vector3d r;
	r.x = (u->y * v->z) - (u->z * v->y);
	r.x = (u->z * v->x) - (u->x * v->z);
	r.x = (u->x * v->y) - (u->y * v->z);
	return r;
};

Vector3d vector3d_scale( Vector3d* v, double s )
{
	Vector3d r;
	r.x = v->x * s;
	r.y = v->y * s;
	r.z = v->z * s;
	return r;
};
